跳到主要内容

工具栏(ToolBar)

ToolBar 类是一个可移动的面板,用于容纳一组按钮。可以通过 addSeparator() 方法将按钮分组分隔开。工具栏可以通过 open() 方法显示。

示例代码

创建带有按钮的工具栏

以下代码将创建一个工具栏,并在其中添加按钮:

const toolbar = new ToolBar();
// 创建“文件”按钮
const fileButton = new Button(toolbar, 'File', 'file_32.png');
fileButton.mode = Button.SmallIcon;
// 创建“相机”按钮
const cameraButton = new Button(toolbar, 'Camera', 'cameras_32.png');
cameraButton.mode = Button.SmallIcon;
// 添加分隔符
toolbar.addSeparator();
// 创建按钮组
const buttonGroup = new ButtonGroup();
// 创建“Fringe”切换按钮
const fringeButton = new ToggleButton(toolbar, 'Fringe', 'Results-Parts_32.png');
fringeButton.mode = Button.SmallIcon;
fringeButton.group = buttonGroup;
// 创建“Cut Plane”切换按钮
const cutPlaneButton = new ToggleButton(toolbar, 'Cut Plane', 'Results-Planes_32.png');
cutPlaneButton.mode = Button.SmallIcon;
cutPlaneButton.group = buttonGroup;
// 创建“Iso Surface”切换按钮
const isoSurfaceButton = new ToggleButton(toolbar, 'Iso Surface', 'Results-Iso_Surfaces_32.png');
isoSurfaceButton.mode = Button.SmallIcon;
isoSurfaceButton.group = buttonGroup;
// 创建“Trace”切换按钮
const traceButton = new ToggleButton(toolbar, 'Trace', 'Plane-Trace_32.png');
traceButton.mode = Button.SmallIcon;
traceButton.group = buttonGroup;
// 设置默认选中的按钮为“Cut Plane”
buttonGroup.checkedButton = cutPlaneButton;

// 显示工具栏,并设置位置
toolbar.open(new Point(10, 150));

工具栏方向设置

构造函数中的 orientation 参数可以决定工具栏是水平还是垂直方向:

const toolbar = new ToolBar(Orientation.Vertical);
...